package com.flyqiu.common.mybaits.plus.properties;

import com.baomidou.mybatisplus.annotation.TableField;
import com.flyqiu.common.property.FlyQiuFieldProperty;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;

@Getter
public class FlyQiuEntityQueryProperty extends FlyQiuFieldProperty {

    private String colName;

    /**
     * 构造一个新的 FlyQiuFieldProperty 对象。
     *
     * @param field            属性字段
     * @param enableHumpNaming 启用或禁用驼峰命名规则
     */
    public FlyQiuEntityQueryProperty(Field field, boolean enableHumpNaming) {
        super(field);
        TableField annotation = this.getAnnotation(TableField.class);
        if (enableHumpNaming) {
            colName = com.baomidou.mybatisplus.core.toolkit.StringUtils.camelToUnderline(getName());
        }
        if (annotation == null) {
            return;
        }
        if (StringUtils.isBlank(annotation.value())) {
            return;
        }
        colName = annotation.value();
    }

}
